<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="{__STATIC_PATH}layuiadmin/layui/css/layui.css" media="all">
    <link rel='stylesheet' href='{__STATIC_PATH}layuiadmin/style/admin.css' media='all'>
    <script src="{__STATIC_PATH}/layuiadmin/layui/layui.js"></script>
    <script>
        layui.config({
            base: '{__STATIC_PATH}layuiadmin/' //静态资源所在路径
        })
    </script>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <form onsubmit="return false;">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">名称</label>
                    <div class="layui-input-inline">
                        <input type="text" name="name" placeholder="请输入"  class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="LAY-app-contlist-search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </div>
        </form>
        <div class="layui-card-body">
            <div style="padding-bottom: 10px;">
                <button class="layui-btn layuiadmin-btn-list" data-type="ok">确定</button>
            </div>
            <table id="table-list" lay-filter="lay-table-list"></table>
        </div>
    </div>
</div>
<script>
    layui.extend({
        index: 'lib/index' //主入口模块
    }).use(['index','table','layer'], function(){
        var table = layui.table
            ,form = layui.form
            ,$ = layui.$
            ,layer = layui.layer;
        var admin = layui.admin;
        var url=decodeURIComponent("{$request->param('request_url')}");
        var tableIns=table.render({
            elem: '#table-list' //指定原始表格元素选择器（推荐id选择器）
            ,url: url //数据接口
            ,page: true //开启分页
            ,height: 'full-180'//高度最大适应
            ,cols: [[
                {type:'checkbox'},
                {type:'numbers',title:'编号'},
                {field:"name",title:"名称",minWidth:100},
                {field:"school_name",title:"学校"},
                {field:"subject_name",title:"学科"},
            ]] //设置表头
            //,…… //更多参数参考右侧目录：基本参数选项
        });
        //监听搜索
        form.on('submit(LAY-app-contlist-search)', function(data){
            var field = data.field;
            //执行重载
            table.reload('table-list', {
                where: field,
                page:{curr:1}
            });
        });
        active = {
            ok: function(){
                var check_data=table.checkStatus('table-list');
                if(check_data.data.length==0){
                    layer.msg('请选择数据');
                }else {
                    var ids="";
                    for(i in check_data.data){
                        ids+=check_data.data[i].id+",";
                    }
                    ids=ids.replace(/,$/,'');
                    field=<?php echo json_encode($request->param());?>;
                    field.ids=ids;
                    admin.req({
                        url: "{$request->param('submit_url')}"
                        ,type: "POST"
                        ,data: field
                        ,datatype:'json'
                        ,success: function(res){
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            if (res.code == 0) {
                                layer.msg('操作成功',{time:500},function(){
                                    parent.layui.table.reload('table-list'); //重载表格
                                    parent.layer.close(index); //再执行关闭
                                });
                            }
                            else {
                                layer.msg(res.msg);
                            }
                        }
                    });
                }
            },
        };
        $('.layui-btn.layuiadmin-btn-list').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
</script>
</body>
</html>